<template>
  <div id="OverCharge" v-loading="loading">
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="tableSelectData"
      :title="$t('in.overchargeInfo1')"
      @receipts="receipts"
    ></v-tableTitle>
    <v-table
      :pageSize="pageSize"
      :page="page"
      :tableConfig="tableConfig"
      :tableData="tableData"
      :total="total"
      @findData="getTableData"
      @getTableData="getTableData"
      @searhData="searhData"
      @selectData="selectData"
      @setdialog="setdialog"
      @upData="getTableData"
      ref="table"
    ></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import drawer from "./deawer/Deawer";
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import bus from "../../../../bus/bus";

export default {
  name: "overCharge",
  mixins: [baseMixin, config],
  data() {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('in.overchargekey'),
          prop: "overchargekey",
          input: "input"
        },
        {
          label: this.$t('in.sellersreference1'),
          prop: "receiptkey",
          input: "input"
        },
        {
          label: this.$t('config.shipper'),
          prop: "storerkey",
          input: "input"
        },
        {
          label: this.$t('config.supplier'),
          prop: "suppliername",
          input: "input"
        },
        {
          label: this.$t('common.status'),
          prop: "status",
          input: "select",
          options: this.getOptions("codelkup/RTXOVERCHARGESTATUS")
        }
      ],
      tableData: [],
      page: 1,
      pageSize: 0,
      total: 0,
      tableSelectData: [],
      tableSearhData: {}
    };
  },
  computed: {
    btnConfig() {
      return [
        { label: this.$t('in.receipts'), certigier: this.createPoASNStatus, disabled: true, invalid: "receipts" }
      ];
    }
  },
  created() {
  },
  methods: {
    async receipts(data) {
      try {
        let res = await this.$api.post(`/createPoASN`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem("page");
          this.getTableData(page, this.tableSearhData);
          this.$refs.table.delSelectData(item, index);
      } catch (e) {
        this.$message.error(e);
      }
    },
    //选中的内容
    selectData(data) {
      this.tableSelectData = data;
    },
    async getTableData(page, data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/queryListOfOvercharge/${page}`, data);
        
          this.loading = false;
          this.tableData = res.page.list;
          this.page = res.page.curPage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
      } catch (e) {
        this.loading = false;
        this.$message.error(e);
      }
    },
    //搜索的值
    searhData(data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
    //设置弹框
    setdialog(data) {
      this.$store.commit("setRouteData", data);
      this.$router.push({ name: "overChargeDeawer" });
    }

  },
  mounted() {
    ;
    this.$store.commit("setSkip", {});
    this.$store.commit("setRouteData", {});
    this.getTableData(1, {});
  },
  watch: {
    tableSelectData(data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.createPoASNStatus = false;
        } else {
          this.createPoASNStatus = true;
        }
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
    "v-drawer": drawer
  }
};
</script>

<style scoped>
#OverCharge {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
